﻿using System;
using System.Configuration;
using KPIS.GERP.Models.SYS.ViewModel;

namespace KPIS.GERP.Models.Class
{
	public static class GerpConfig
	{

		#region Declaration
		
		private static AppSettingsReader _settingsReader = new AppSettingsReader();
		
		#endregion


		#region General Use Config Reader

		public static string GetByEntryName(string entryName)
		{
			return (string)_settingsReader.GetValue(entryName, typeof(string));
		}

		public static int? GetIntValueByEntryName(string entryName)
		{
            try
            {
                return (int?) _settingsReader.GetValue(entryName, typeof (int?));
            } catch (Exception ex)
            {
                GerpLog.ArgumentNullException("entryName", ex.Message);
                return null;
            }
		}

		public static string GetConnectionString(string entryName)
		{
			try
			{
				return ConfigurationManager.ConnectionStrings[entryName].ConnectionString;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		} 
		#endregion


		#region Get value of web.config (remark- value must be set in web.config of Web you're call, not in model)

		public static int UserExpireInMinutes
		{
			get { return GetIntValueByEntryName("UserExpireInMinutes") ?? 5;   }
		}

		#endregion


	}
}
